/*
 * Copyright (C) 2017 Qi Cai Technology Co., Ltd. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package com.www.ww.huitouke;

import android.app.Application;
import android.util.Log;

import com.example.lkslib.lksBus.EventHelper;
import com.example.lkslib.lksBus.LKsUrlInit;
import com.example.lkslib.lksBus.UrlBean;
import com.example.lkslib.router.Router;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.view.CropImageView;
import com.www.ww.main.utils.GlideImageLoader;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * TODO this class desription here
 * <p>
 * Created by ww on 2017/8/10.
 */
public class HTKApplication extends android.support.multidex.MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        EventBus.getDefault().register(this);
        Router.init(this);
        LKsUrlInit.init(this);

        initImagePicker();
    }

    private void initImagePicker() {
        ImagePicker imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new GlideImageLoader());   //设置图片加载器
        imagePicker.setShowCamera(true);  //显示拍照按钮
        imagePicker.setCrop(true);        //允许裁剪（单选才有效）
        imagePicker.setSaveRectangle(true); //是否按矩形区域保存
        imagePicker.setSelectLimit(4);    //选中数量限制
        imagePicker.setStyle(CropImageView.Style.RECTANGLE);  //裁剪框的形状
        imagePicker.setFocusWidth(800);   //裁剪框的宽度。单位像素（圆形自动取宽高最小值）
        imagePicker.setFocusHeight(800);  //裁剪框的高度。单位像素（圆形自动取宽高最小值）
        imagePicker.setOutPutX(1000);//保存文件的宽度。单位像素
        imagePicker.setOutPutY(1000);//保存文件的高度。单位像素
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMainEvent(UrlBean urlBean) {
        try {
            EventHelper.handlerEvent(urlBean);
        } catch (NoSuchMethodException e) {
            Log.e("LKS", "@LksUrl 只能用于在LksServlet");
            e.printStackTrace();
        }
    }

}
